<script>
import { mapState, mapActions } from 'vuex';

export default {
    data() {
        return {
            // 初始化 update 对象以避免 undefined 引用
            update: {
                download: {
                    start: false,
                    install: false,
                    progress: 0,
                    totalBytesWritten: 0,
                    totalBytesExpectedToWrite: 0
                }
            }
        };
    },
    computed: {
        ...mapState('common', ['modulesData']),
        ...mapState('cart', ['showStoreRecommend'])
    },
    onLaunch() {
        this.fetchShowStoreRecommend();
        this.updateDynamicTabBar();
    },
    methods: {
        ...mapActions('cart', ['fetchShowStoreRecommend']),
        async updateDynamicTabBar() {
            const tabBarList = [{
                    pagePath: "pages/index",
                    iconPath: "static/images/tabbar/index.png",
                    selectedIconPath: "static/images/tabbar/indexHL.png",
                    text: "主页"
                },
                {
                    pagePath: "pages/category",
                    iconPath: "static/images/tabbar/category.png",
                    selectedIconPath: "static/images/tabbar/categoryHL.png",
                    text: "分类"
                },
                {
                    pagePath: "pages/cart",
                    iconPath: "static/images/tabbar/cart.png",
                    selectedIconPath: "static/images/tabbar/cartHL.png",
                    text: "购物车"
                },
                {
                    pagePath: "pages/user",
                    iconPath: "static/images/tabbar/user.png",
                    selectedIconPath: "static/images/tabbar/userHL.png",
                    text: "我的"
                }
            ];

            if (this.showStoreRecommend) {
                tabBarList.splice(2, 0, {
                    pagePath: "pages/find",
                    iconPath: "static/images/tabbar/find.png",
                    selectedIconPath: "static/images/tabbar/findHL.png",
                    text: "发现"
                });
            }

            uni.setStorageSync("dynamicTabBar", tabBarList);
            uni.reLaunch({
                url: '/pages/index'
            });
        }
    }
};
</script>